var tinify = require("tinify");
require('babel-polyfill')
tinify.key = "_53YkYKYVHhKZihlAckkBWciYpRtit1P";

var fs = require("fs");
var path = require('path')
fs.readdir(path.resolve(__dirname, 'img'), function(err, sourceData) {
  sourceData.forEach(val => {
    const source = tinify.fromFile(path.resolve(__dirname, 'img', val))
    source.toFile(path.resolve(__dirname, 'img', val));
    // var copyrighted = source.preserve("copyright", "creation");
    // copyrighted.toFile("optimized-copyright.jpg");
  })
  // if (err) throw err;
});
